package com.wf.it.common.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

@ApiModel(value="Result<T>-封装结果的VO类")
public class Result<T> implements Serializable {
    @ApiModelProperty("状态")
    private int state=200;
    @ApiModelProperty("具体数据")
    private T obj;
    @ApiModelProperty("附带消息")
    private String msg="ok";

    public static <T> Result<T> success(T data) {
        return new Result(200,data,"ok");
    }
    private static Result successResult=null;
    public static Result success() {
        if(successResult==null)
            successResult=new Result(200,null,"ok");
        return successResult;
    }
    private static Result notpowerResult= new Result(403,null,"has not power to do!");
    public static Result notPower() {
        return notpowerResult;
    }

    public static Result FAIL= new Result(500,null,"opr is fail");
    public static Result fail() {
        return FAIL;
    }
    public static Result fail(String errMsg) {
        return new Result(500,null,errMsg);
    }

    public static Result needLogin(){
        return new Result(401,null,"you need to login");
    }

    public Result() {
    }

    public Result(T obj) {
        this.obj = obj;
    }
    public Result(int state, T obj, String msg) {
        this.state = state;
        this.obj = obj;
        this.msg = msg;
    }



    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public T getObj() {
        return obj;
    }

    public void setObj(T obj) {
        this.obj = obj;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
